<?php 
//file included with update
//put all slot names into an array
$slot_a = array('head','neck','shoulder','back','chest','shirt','tabard','wrist','hands','waist','legs','feet','finger1','finger2','trinket1','trinket2','mainHand','offHand','ranged');

$item=0;

		while ($item <= 18)//iterate through slot array
		{
		$charItems = $character['items'][$slot_a[$item]];
		
			if ($charItems==True)
			{
				$slot=$slot_a[$item];
				$itemId=$charItems['id'];
				//find most recent item in that slot
				$sqlOldItem = "SELECT item_id FROM char_history_items ci inner join char_history c ON
				ci.char_history_id = c.char_history_id
				WHERE slot = ? AND c.char_id = ?
				ORDER BY ci.char_history_id DESC
				LIMIT 0,1
				";
				
				$pdo->bound_query($sqlOldItem,array($slot,$char_id),'One');
				$sqlOldItemId = $pdo->result;
		
				if ($sqlOldItemId[0]==$itemId)
				{
				echo "Item slot: " . $slot . " not updated.<br/>";
				}//do not update slot
				else
				{
					$name=$charItems['name'];
					$rarity=$charItems['quality'];
					$url=$charItems['icon'];
					$sqlInsertItems = "INSERT into char_history_items (char_history_id, slot, item_id, level, name, rarity, url, 						datestamp, userstamp) VALUES (?,?,?,?,?,?,?,(select curdate()),1)";
					
					$pdo->bound_query($sqlInsertItems,array($charHistoryId,$slot,$itemId,$level,$name,$rarity,$url),'None','InsertItems');
					$insertItem = $pdo->rownum;	
					 if (empty($insertItem))
					 {
					 echo "<td>Items record for " . $slot . " could not be inserted: " . $err . "</td><br/>";}
					 else 
					 {
					 echo "<td>Item slot: " . $slot . " updated.</td><br/>";
					
					 }
				}
			}
			else
			{
			echo "<td>Item slot: " . $slot . " not found.</td><br/>";
			}
		$item++;
		//unset($slot, $itemId, $level, $name, $rarity, $url);
		}





?>